﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

using Winsteps.Validator;//引用asp.net的验证控件

public partial class baoming : System.Web.UI.Page
{
    BLL.ProfessionalBll proBll = new BLL.ProfessionalBll();
    BLL.RegistrationBll regBll = new BLL.RegistrationBll();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadValidator();

            BindProfessional();
        }
    }

    private void BindProfessional()
    {
        DataTable table = proBll.GetAllProfessional();
        ddl_Professional.DataSource = table;
        ddl_Professional.DataBind();
    }
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        string code = Session["code"].ToString();
        if (code == txt_Verify.Text.ToString())
        {
            Model.Registration reg = new Model.Registration();
            reg.proId = ddl_Professional.Text.ToString();
            reg.regName = txt_Name.Text.ToString();
            if (RadioButtonN.Checked)
            {
                reg.regSex = RadioButtonN.Text.ToString();
            }
            else
            {
                reg.regSex = RadioButtonL.Text.ToString();
            }
            reg.regBirthday = txt_Birthday.Text.ToString();
            reg.regNative = txt_Native.Text.ToString();
            reg.regDegree = txt_Degree.Text.ToString();
            reg.regSchool = txt_School.Text.ToString();
            reg.regAccount = txt_Account.Text.ToString();
            reg.regAddress = txt_Address.Text.ToString();
            reg.regZip = txt_Zip.Text.ToString();
            reg.regPhone = txt_Phone.Text.ToString();
            reg.regMail = txt_Mail.Text.ToString();
            reg.regIDCard = txt_IDCard.Text.ToString();

            if (regBll.AddRegistration(reg))
            {
                //ClientScript.RegisterClientScriptBlock(this.GetType(), "s", "alert('提交成功')", true);
                this.Response.Write(" <script>alert('提交成功'); window.location.href=window.location.href; </script> ");
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "s", "alert('提交失败')", true);
            }
        }
        else
        {
            txt_Verify.Focus();
        }
    }

    //加载验证
    private void LoadValidator()
    {
        WinVal WinValInstance = new WinVal();
        WinValInstance.SetValidator();

        txt_Name.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Name.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_Account.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Account.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_Address.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Address.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_Birthday.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Birthday.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_Degree.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Degree.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_IDCard.Attributes.Add("onblur", "this.className='inputblur'");
        txt_IDCard.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_Mail.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Mail.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_Native.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Native.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_Phone.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Phone.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_School.Attributes.Add("onblur", "this.className='inputblur'");
        txt_School.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_Verify.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Verify.Attributes.Add("onfocus", "this.className='inputfoucs'");

        txt_Zip.Attributes.Add("onblur", "this.className='inputblur'");
        txt_Zip.Attributes.Add("onfocus", "this.className='inputfoucs'");
    }
}
